# $Id$
# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: Anton Bazhenov <anton.bazhenov at gmail>
# Contributor: Jaroslav Lichtblau <dragonlord@aur.archlinux.org>
# Contributor: Gilles Gagniard <gilles@gagniard.org>
# Contributor: JD Steffen <jd at steffennet dot org>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - get rid of a bad gcc flag in Makefile

pkgname=simutrans
pkgver=120.0.1
_pkgver=120-0-1
pkgrel=2
pkgdesc="An open source transportation simulation game"
arch=('i686' 'x86_64')
url="http://simutrans.com/"
license=('custom:Artistic')
depends=('gcc-libs' 'zlib' 'sdl_mixer' 'bzip2' 'simutrans-pak64')
makedepends=('imagemagick' 'dos2unix')
optdepends=('timidity++: play MIDI music')
source=(http://downloads.sourceforge.net/$pkgname/$pkgname-src-$_pkgver.zip
        no-optimise.patch
        settings-folder.patch
        path-for-game-data.patch
        config.patch
        simutrans.desktop)
md5sums=('40372b6417f235740b14a6bb7b389a78'
         '34b0472b08f3d9f38e289ba1639ef232'
         'c87d9a9910bc371df5d50f7f1ec298bb'
         'e716340d372af264ca05510facfe5d2c'
         'c2f4e494168e235380373974c91a0803'
         'f41f7a08ad517ef2b60412859eb49963')

prepare() {
  cd "$srcdir"

  # Some files are distributed in DOS format
  find . -type f -exec dos2unix -q '{}' \;

  # Don't overwrite default optimization flags
  patch -Np1 -i no-optimise.patch

  # Adjust paths
  patch -Np0 -i settings-folder.patch
  patch -Np1 -i path-for-game-data.patch

  # Configure the build process
  cp config.template config.default
  patch -Np0 -i config.patch

  sed -i 's/-minline-all-stringops/-O3/' Makefile
}

build() {
  cd "$srcdir"
  convert simutrans.ico -alpha on simutrans.png
  make
}

package() {
  cd "$srcdir"

  #binary
  install -Dm755 build/default/sim "$pkgdir/usr/bin/simutrans"

  #data
  mkdir -p "$pkgdir/usr/share/games/$pkgname"
  cp -r $pkgname/{config,font,music,text,themes} "$pkgdir/usr/share/games/$pkgname"

  #desktop file and icon
  install -Dm644 simutrans.png "$pkgdir/usr/share/pixmaps/simutrans.png"
  install -Dm644 simutrans.desktop "$pkgdir/usr/share/applications/simutrans.desktop"

  #license
  install -Dm644 simutrans/license.txt "$pkgdir/usr/share/licenses/simutrans/license.txt"
}
